import time, subprocess


class screenShot(object):
    def __init__(self):
        self.cmd_shot = 'adb shell screencap -p /sdcard/screen.png'
        # 电脑路径、中文编码问题
        self.cmd_pull = "adb pull /sdcard/screen.png D:/123"
        self.nowtime = time.strftime('%Y%m%d_%H%M%S', time.localtime())

    def Run(self):
        print('开始截图')
        res1 = subprocess.getstatusoutput(self.cmd_shot)
        if res1[0] == 0:
            print('截图成功,开始导出')

        text = self.cmd_pull + '\\screen' + self.nowtime + '.png'
        res2 = subprocess.getstatusoutput(text)
        if 'B/s' in res2[1]:
            print('导出成功')
        else:
            print('导出失败')
            print(res2[1])


if __name__ == '__main__':
    sc = screenShot()
    sc.Run()
    time.sleep(5)
